// 大病保障-保障概览
import { http } from "@/utils/http";
import { globalDataStoreHook } from "@/store/modules/globalData";
import { whReqBaseUrl as VITE_REQUEST_BASE_SAAS_API } from "@/api/common";
const initCityId = globalDataStoreHook().cityId;

import { type basicUserQueryType } from "@/api/types";
import { useUserStoreHook } from "../store/modules/user";

type userAnalysisQueryDataType = basicUserQueryType & {
  startDate: string;
  endDate: string;
};

type overviewDataType = {
  newInsuranceCount: number; //新增保障（人）
  inInsuranceCount: number; //在保人数（人）
  cumulativeInsuredCount: number; //累计保障人数（人）
  insuranceAccidentCount: number; //出险人数（人次）
  reimbursementAmount: string; //额外报销金额（元）
};

type trendDataType = {
  sections: Array<string>; //日期数组
  newInsuranceCount: Array<number>; //新增保障（人）
  inInsuranceCount: Array<number>; //在保人数（人）
  cumulativeInsuredCount: Array<number>; //累计保障人数（人）
  insuranceAccidentCount: Array<number>; //出险人数（人次）
  reimbursementAmount: Array<string>;
};

type dateType = 1 | 2 | 3; // 类型 1=按日 2=按周 3=按月
// 保障概览
export function getInsuranceOverview(data: userAnalysisQueryDataType) {
  return http.get<overviewDataType>(
    `${VITE_REQUEST_BASE_SAAS_API}/stat/insuranceOverview`,
    {
      params: {
        ...data
      }
    }
  );
}

// 保障概览趋势分析

export function getInsuranceTrendData(
  data: userAnalysisQueryDataType & { type: dateType }
) {
  let queryUrl = "/stat/insuranceOverview/trend";
  if (useUserStoreHook().mock === "1") {
    queryUrl = "/stat/insuranceTrend";
  }
  return http.get<trendDataType>(`${VITE_REQUEST_BASE_SAAS_API}${queryUrl}`, {
    params: {
      ...data
    }
  });
}

// 在保分析
type inInsuranceDataType = {
  ages: Array<{ title: string; value: number }>;
  complications: Array<{ title: string; value: number }>;
};
export function getInInsuranceData(data: userAnalysisQueryDataType) {
  return http.get<inInsuranceDataType>(
    `${VITE_REQUEST_BASE_SAAS_API}/stat/inInsurance`,
    {
      params: {
        ...data
      }
    }
  );
}
